package com.spring.sunflower.dialog

import android.content.Context
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import com.bumptech.glide.Glide
import com.lxj.xpopup.core.CenterPopupView
import com.spring.sunflower.R

/**
 * Created by Kevin on 2021/8/6<br/>
 *
 * Describe:<br/>
 */
class SignInDialog(
    context: Context,
    var layoutID: Int,
) : CenterPopupView(context) {
    private var clGift: ConstraintLayout? = null
    private var llSigned: LinearLayout? = null
    private var tvDonate: TextView? = null
    private var tvDone: TextView? = null
    private var llDone: LinearLayout? = null
    private var hasSigned = false
    private var ivMoney:ImageView?=null
    override fun getImplLayoutId(): Int {
        return layoutID
    }

    override fun onCreate() {
        super.onCreate()
        clGift = findViewById<ConstraintLayout>(R.id.clGift)
        llSigned = findViewById(R.id.llSigned)
        tvDonate = findViewById(R.id.tvDonate)
        llDone = findViewById(R.id.llDone)
        tvDone = findViewById(R.id.tvDone)
        ivMoney = findViewById(R.id.ivMoney)
        val ivClose = findViewById<ImageView>(R.id.ivClose)
        ivClose.setOnClickListener { dismiss() }
        llDone?.setOnClickListener {
            if (hasSigned) {
                listener?.onOKClick()
            } else {
                listener?.onSignClick()
            }
        }
    }

    private var listener: OnSignInListener? = null
    fun setOnSignInListener(l: OnSignInListener) {
        listener = l
    }

    interface OnSignInListener {
        fun onSignClick()//立即签到
        fun onOKClick()//我知道了
    }

    fun setDoneText(str: String) {
        tvDone?.text = str
    }

    fun showGiftBag() {
        llSigned!!.visibility = INVISIBLE
        clGift!!.visibility = VISIBLE
    }

    fun showSignSuccess(donate: String,gender:String) {
        llSigned!!.visibility = VISIBLE
        clGift!!.visibility = INVISIBLE
        tvDonate!!.text = "x${donate}"
        tvDone!!.text = "我知道了"
        Glide.with(context)
            .load(if ("1" == gender) R.drawable.ic_money else R.drawable.ic_income_diamond)
            .placeholder(R.drawable.ic_placeholder)
            .into(ivMoney!!)
    }

    fun setHasSigned(b: Boolean) {
        hasSigned = b;
    }
}